
package com.example.paper.testCache;


import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 缓存测试Controller
 */
@RestController
@Slf4j
public class TestSpringCacheController {


    /**
     * 测试Spring Cacheable,通过postman调用多次，查看日志，发现内部逻辑只调用一次，之后的调用都是从缓存中获取
     * @return String
     * @throws InterruptedException
     */
    @GetMapping(path = "getHostAirlineCode")
    @Cacheable({"getHostAirlineCode"})
    public String getHostAirlineCode() throws InterruptedException {
        log.info("调用内部逻辑");
        // 模拟网络IO
        Thread.sleep(1000L);
        return "CA";
    }

}
